<template>
  <div class="app-container">
    <div class="searchBox">
      <el-form :inline="true" :model="search">
        <el-form-item label="标题" prop="appTitle">
          <el-input
            v-model="search.appTitle"
            placeholder="请输入标题"
            clearable
            size="small"
            @keyup.enter.native="searchQuery"
          />
        </el-form-item>
        <el-form-item label="分类" prop="appCategory">
          <el-select
            v-model="search.appCategory"
            placeholder="请选择分类"
            clearable
            size="small"
          >
            <el-option
              v-for="item in controlData.appCategoryDictItems"
              :value="item.code"
              :label="item.name"
              :key="item.code"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="作者" prop="appAuthor">
          <el-input
            v-model="search.appAuthor"
            placeholder="请输入作者"
            clearable
            size="small"
            @keyup.enter.native="searchQuery"
          />
        </el-form-item>
        <el-form-item style="margin-top: -2px">
          <el-button type="primary" @click="searchQuery">搜索</el-button>
          <el-button
            type="info"
            @click="
              search = {};
              searchQuery();
            "
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </div>

    <qm-table
      ref="marketAppTable"
      :data="query"
      keyProp="appId"
      menuType="text"
      :showCheckbox="false"
      :showOrder="false"
      :showFormFooter="false"
      isCustomForm
      :viewFunc="onAppViewFunc"
    >
      <qm-table-column field="appTitle">标题</qm-table-column>
      <qm-table-column
        field="appCategory"
        fieldType="dict"
        :dictOptions="controlData.appCategoryDictItems"
      >
        分类
      </qm-table-column>
      <qm-table-column field="appAbstract">摘要</qm-table-column>
      <qm-table-column field="appAuthor">作者</qm-table-column>
      <qm-table-column field="currentVersion"> 当前版本 </qm-table-column>
      <qm-table-column field="svnUrl">SVN地址</qm-table-column>
      <qm-table-column field="createUserName">创建人名称</qm-table-column>
      <qm-table-column field="createTime" fieldType="date">
        创建时间
      </qm-table-column>

      <template v-slot:form="{ viewModel, formData, controlData, pageAction }">
        <app-operate
          ref="create"
          :viewModel="viewModel"
          :model="formData"
          :controlData="controlData"
          :pageAction="pageAction"
        ></app-operate>
      </template>
    </qm-table>
  </div>
</template>

<script>
import Controller from "@/libs/framework/controller";
import AppOperate from "./appOperate";

export default class Instance extends Controller {
  onBeforeInit() {
    this.urls = {
      model: "/eip/marketApp/getListModel",
      query: "/eip/marketApp/query",
    };
  }

  mixin() {
    return {
      components: {
        AppOperate,
      },
      methods: {
        onAppViewFunc(app) {
          // TODO 临时修改
          // window.open("/eip/marketApp/detail?appId=" + app.appId);
          this.$router.push("/eip/marketApp/detail?appId=" + app.appId);
        },
      },
    };
  }
}
</script>
